package com.project.controller;

import com.project.bean.CutPageBean;
import com.project.bean.PostBean;
import com.project.bean.UserBean;
import com.project.servic.IPostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDate;
import java.util.List;

@RestController
@RequestMapping("post")
public class PostController {
    @Autowired
    private IPostService service;
@RequestMapping("findByItem")
    public CutPageBean<PostBean> findByItem (Integer channelId, Integer pageNo, String userName, String postName, LocalDate startDate, LocalDate endDate){
        return service.findChannelById(channelId,  pageNo, userName, postName,  startDate, endDate);
    }
    @RequestMapping("findById")
    public PostBean findById(Integer id){
    return service.findById(id);
    }
@RequestMapping("add")
    public String add (String postName, String postContent, Integer channel, HttpServletRequest req){
        //从session中得到登陆用户
        UserBean user = (UserBean) req.getSession().getAttribute("loginUser");
        PostBean post = new PostBean(postName,user.getId(),postContent,channel);
         service.add(post);
        return "ok";
    }
}
